#include<iostream>
using namespace std;
const int N = 110;
int f[N][N];
int g[N][N];
int n, m;
int main()
{
	cin >> n >> m;
	memset(g, -0x3f, sizeof(g));
	memset(f, -0x3f, sizeof(f));
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cin >> g[i][j];
			f[i][j] = 1;
		}
	}
	int ma = -1e9;
	for (int i = n; i >= 1; i--) {	
		for (int j = m; j >= 1; j--) {
			if (g[i - 1][j] > g[i][j]) {
				f[i - 1][j] = max(f[i - 1][j], f[i][j] + 1);
			}
			if (g[i][j + 1] > g[i][j]) {
				f[i][j + 1] = max(f[i][j + 1], f[i][j] + 1);
			}
			if (g[i + 1][j] > g[i][j]) {
				f[i + 1][j] = max(f[i + 1][j], f[i][j] + 1);
			}
			if (g[i][j - 1] > g[i][j]) {
				f[i][j - 1] = max(f[i][j - 1], f[i][j] + 1);
			}
			ma = max(f[i][j], ma);
		}
	}
	//cout << f[1][1] << endl;
	cout << f[2][1] << endl;
	cout << ma << endl;
	return 0;
}